package com.stylefeng.guns.modular.flagglory.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.common.persistence.model.Setting;
import com.stylefeng.guns.modular.flagglory.service.ISettingService;

/**
 * 设置信息控制器
 *
 * @author fengshuonan
 * @Date 2018-02-27 16:00:51
 */
@Controller
@RequestMapping("/setting")
public class SettingController extends BaseController {

    private String PREFIX = "/flagGlory/setting/";

    @Autowired
    private ISettingService settingService;

    /**
     * 跳转到设置信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "setting.html";
    }

    /**
     * 跳转到添加设置信息
     */
    @RequestMapping("/setting_add")
    public String settingAdd() {
        return PREFIX + "setting_add.html";
    }

    /**
     * 跳转到修改设置信息
     */
    @RequestMapping("/setting_update/{settingId}")
    public String settingUpdate(@PathVariable Integer settingId, Model model) {
        Setting setting = settingService.selectById(settingId);
        model.addAttribute("item",setting);
        LogObjectHolder.me().set(setting);
        return PREFIX + "setting_edit.html";
    }

    /**
     * 获取设置信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return settingService.selectList(null);
    }

    /**
     * 新增设置信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Setting setting,boolean isShow) {
        setting.setShow(isShow);
        settingService.insert(setting);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除设置信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer settingId) {
        settingService.deleteById(settingId);
        return SUCCESS_TIP;
    }

    /**
     * 修改设置信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Setting setting) {
        settingService.updateById(setting);
        return super.SUCCESS_TIP;
    }

    /**
     * 设置信息详情
     */
    @RequestMapping(value = "/detail/{settingId}")
    @ResponseBody
    public Object detail(@PathVariable("settingId") Integer settingId) {
        return settingService.selectById(settingId);
    }
}
